// #packager-optimize

(function() {

    var ObserverClass = function() {

        var handlersData = {};

        this.addEventHandler = function(eventName, handler, ctx) {
            handlersData[eventName] = handlersData[eventName] || [];
            handlersData[eventName].push({ handler : handler, context : ctx });
        };

        this.subscribe = function(eventName, handler, ctx) {
            if (typeof eventName == 'string') {
                this.addEventHandler(eventName, handler, ctx);
                return;
            }

            var i, currentEvent;

            for (i = 0; i < eventName.length; ++i) {
                currentEvent = eventName[i];
                this.addEventHandler(currentEvent.name, currentEvent.handler, currentEvent.context);
            }
        };

        this.notify = function(eventName, eventData) {
            var eventHandlersData = handlersData[eventName];

            if (eventHandlersData) {
                var i;
                for (i = 0; i < eventHandlersData.length; ++i) {
                    var data = eventHandlersData[i];
                    data.handler.call(data.context, eventData);
                }
            }
        };

    };

    juliet.registerModule('juliet.core', 'Observer-0.1', ObserverClass);

})();
